package yx.action;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.springframework.beans.factory.annotation.Autowired;

import yx.service.EducationServiceInt;
import yx.vo.EducationVO;
import yx.vo.JsonVO;

import com.opensymphony.xwork2.ModelDriven;

@ParentPackage("basePackage")
@Namespace("/")
@Action(value = "educationAction")
public class EducationAction extends BaseAction implements ModelDriven<EducationVO> {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(EducationAction.class);

	private EducationVO education = new EducationVO();

	@Override
	public EducationVO getModel() {
		return education;
	}

	private EducationServiceInt educationService;

	public EducationServiceInt getEducationService() {
		return educationService;
	}
	
	@Autowired
	public void setEducationService(EducationServiceInt educationService) {
		this.educationService = educationService;
	}

	public void queryEducation() {
		/*
		 * TODO：需要调查为什么加判定
		 */
		if (education.getStudentId() != null) {
			super.writeJson(educationService.datagrid(education));
		}
	}

	public void addEducation() {
		JsonVO j = new JsonVO();
		try {
			EducationVO u = educationService.save(education);
			j.setSuccess(true);
			j.setMsg("增加成功！");
			j.setObj(u);
		} catch (Exception e) {
			j.setMsg(e.getMessage());
		}
		super.writeJson(j);
	}

	public void removeEducation() {
		educationService.remove(education.getIds());
		JsonVO j = new JsonVO();
		j.setSuccess(true);
		j.setMsg("删除成功！");
		super.writeJson(j);
	}

	public void editEducation() {
		EducationVO u = educationService.edit(education);
		JsonVO j = new JsonVO();
		j.setSuccess(true);
		j.setMsg("编辑成功！");
		j.setObj(u);
		super.writeJson(j);
	}

}
